import React, {useState, useEffect} from 'react';
function ExampleHook3(){
  const [count, setCount] = useState(0)
  useEffect(()=>{ // 等于componentDidMount + componentDidUpdate，且是异步的，解决hook没有生命周期的问题
    console.log(`useEffect=>You clicked ${count} times`)
  })
  return (
    <div>
      <p>You clicked {count} times</p>
      <button onClick={()=>{setCount(count+1)}}>click me</button>
    </div>
  )
}

/* import React, { Component } from 'react';
class ExampleHook3 extends Component{
  constructor(props){
    super(props)
    this.state = {count: 0}
  }
  componentDidMount(){
    console.log(`componentDidMount=>You clicked ${this.state.count}`)
  }
  componentDidUpdate(){
    console.log(`componentDidUpdate=>You clicked ${this.state.count}`)
  }
  render(){
    return(
      <div>
        <p>You click {this.state.count} times</p>
        <button onClick={this.addCount.bind(this)}>click me</button>
      </div>
    )
  }
  addCount(){
    this.setState({count: this.state.count+1})
  }
}*/
export default ExampleHook3 